package mine.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.whu.administrator.ws.MyApplication;
import com.whu.administrator.ws.R;

import java.util.ArrayList;
import java.util.List;

import model.NoteBook;

/**
 * 记事本
 * Created by Administrator on 2016/3/19.
 */
public class NoteBookAdapter extends BaseAdapter {

    List<NoteBook> noteBooks = new ArrayList<NoteBook>();

    public void setNoteBooks(List<NoteBook> noteBooks) {
        this.noteBooks = noteBooks;
    }

    @Override
    public int getCount() {
        return noteBooks.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null)
        {
            viewHolder = new ViewHolder();
            convertView = View.inflate(MyApplication.share(),R.layout.item_notebooksimple,null);
            viewHolder.tv_time = (TextView) convertView.findViewById(R.id.id_tv_time);
            viewHolder.tv_title = (TextView) convertView.findViewById(R.id.id_tv_title);
            convertView.setTag(viewHolder);
        }
        else
        {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        NoteBook noteBook = noteBooks.get(position);
        viewHolder.tv_time.setText(noteBook.getTime());
        viewHolder.tv_title.setText(noteBook.getTitle());
        convertView.setTag(R.id.id_notebook,noteBook);
        return convertView;
    }

    public static class ViewHolder {
        public TextView tv_time;
        public TextView tv_title;
    }
}
